﻿using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Drawing;
using System.Linq;
using System.Threading;
using System.Threading.Tasks;
using System.Windows.Forms;
using BaseDll;
using CommonTools;
using MotionIoLib;
using Sunny.UI;
using UserCtrl;
using System.Reflection;
namespace StationDemo
{
    public partial class StationFormSixRobot : UIPage
    {
        public BaseSixRobot SixRobot = null;
        private readonly Stationbase _stationBase;
        private object obj_Param = null;
        private object obj_Point = null;
        private object obj_Joint = null;
        private UIPage Page_Manual = null;
        string strCoordName = "世界坐标系";
        public StationFormSixRobot(BaseSixRobot robot,Stationbase stationbase,object obj_Param, object obj_Point, object obj_Joint, object obj_Config, UIPage ui_Manual = null)
        {
            InitializeComponent();
            SixRobot = robot;
            _stationBase = stationbase;
            this.obj_Point = obj_Point;
            this.obj_Joint = obj_Joint;
            this.obj_Param = obj_Param;
            propertyGrid_Config.SelectedObject = obj_Config;
            Page_Manual = ui_Manual;
        }
        private void button_Save_Click(object sender, EventArgs e)
        {
            string strPointNameErr = "";
            try
            {
                if (!this.ShowAskDialog("是否保存所有点位！", UIStyle.Blue)) return;
                if(cbb_CoordType.Text == "世界坐标系")
                {
                    Dictionary<string, SixRobotPoint> staPoint_New = new Dictionary<string, SixRobotPoint>();
                    Dictionary<string, SixRobotPoint> staPoint_Old = _stationBase.GetFields<SixRobotPoint>(obj_Point);
                    for (int i = 0; i < dataGridView_PointInfo.Rows.Count; i++)
                    {
                        if (dataGridView_PointInfo.Rows[i].Cells[0].Value != null && dataGridView_PointInfo.Rows[i].Cells[0].Value.ToString() != "")
                        {
                            int index = 1;
                            SixRobotPoint point = new SixRobotPoint();
                            string strName = Language.LanguageHelp.GetInstance().Function_TransToChinese(this.Name, dataGridView_PointInfo.Rows[i].Cells[0].Value.ToString());
                            point.X = Convert.ToDouble(dataGridView_PointInfo.Rows[i].Cells[index++].Value);
                            point.Y = Convert.ToDouble(dataGridView_PointInfo.Rows[i].Cells[index++].Value);
                            point.Z = Convert.ToDouble(dataGridView_PointInfo.Rows[i].Cells[index++].Value);
                            point.W = Convert.ToDouble(dataGridView_PointInfo.Rows[i].Cells[index++].Value);
                            point.P = Convert.ToDouble(dataGridView_PointInfo.Rows[i].Cells[index++].Value);
                            point.R = Convert.ToDouble(dataGridView_PointInfo.Rows[i].Cells[index++].Value);
                            string str_PointInfo = $"世界坐标系 站位名称：{this.Name}，点位名称：{strName},X={point.X}，Y={point.Y}，Z={point.Z}，W={point.W},P={point.P},R={point.R}";
                            staPoint_New.Add(strName, point);
                        }
                    }
                    if (obj_Point == null) return;
                    FieldInfo[] list_Field = obj_Point.GetType().GetFields(BindingFlags.NonPublic | BindingFlags.Public | BindingFlags.Instance);
                    if (list_Field.Length <= 0) return;
                    foreach (var item in list_Field)
                    {
                        string str_Name = item.Name;
                        for (int i = 0; i < staPoint_New.Count; i++)
                        {
                            if (item.Name == staPoint_New.Keys.ToList()[i])
                            {
                                item.SetValue(obj_Point, staPoint_New.Values.ToList()[i]);
                            }
                        }
                    }
                    ConfigToolMgr.GetInstance().SaveSixRobotPoint(this.Name, staPoint_New);
                }
                else
                {
                    Dictionary<string, SixRobotJoint> staPoint_New = new Dictionary<string, SixRobotJoint>();
                    Dictionary<string, SixRobotJoint> staPoint_Old = _stationBase.GetFields<SixRobotJoint>(obj_Joint);
                    for (int i = 0; i < dataGridView_PointInfo.Rows.Count; i++)
                    {
                        if (dataGridView_PointInfo.Rows[i].Cells[0].Value != null && dataGridView_PointInfo.Rows[i].Cells[0].Value.ToString() != "")
                        {
                            int index = 1;
                            SixRobotJoint point = new SixRobotJoint();
                            string strName = dataGridView_PointInfo.Rows[i].Cells[0].Value.ToString();
                            point.A1 = Convert.ToDouble(dataGridView_PointInfo.Rows[i].Cells[index++].Value);
                            point.A2 = Convert.ToDouble(dataGridView_PointInfo.Rows[i].Cells[index++].Value);
                            point.A3 = Convert.ToDouble(dataGridView_PointInfo.Rows[i].Cells[index++].Value);
                            point.A4 = Convert.ToDouble(dataGridView_PointInfo.Rows[i].Cells[index++].Value);
                            point.A5 = Convert.ToDouble(dataGridView_PointInfo.Rows[i].Cells[index++].Value);
                            point.A6 = Convert.ToDouble(dataGridView_PointInfo.Rows[i].Cells[index++].Value);
                            string str_PointInfo = $"关节坐标系 站位名称：{this.Name}，点位名称：{strName},X={point.A1}，Y={point.A2}，Z={point.A3}，W={point.A4},P={point.A5},R={point.A6}";
                            staPoint_New.Add(strName, point);
                        }
                    }
                    if (obj_Joint == null) return;
                    FieldInfo[] list_Field = obj_Joint.GetType().GetFields(BindingFlags.NonPublic | BindingFlags.Public | BindingFlags.Instance);
                    if (list_Field.Length <= 0) return;
                    foreach (var item in list_Field)
                    {
                        string str_Name = item.Name;
                        for (int i = 0; i < staPoint_New.Count; i++)
                        {
                            if (item.Name == staPoint_New.Keys.ToList()[i])
                            {
                                item.SetValue(obj_Joint, staPoint_New.Values.ToList()[i]);
                            }
                        }
                    }
                    ConfigToolMgr.GetInstance().SaveSixRobotJoint(this.Name, staPoint_New);

                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(Name, $"{Name}{ex.Message} {ex.StackTrace}");
                this.ShowErrorDialog($"点位数据：{strPointNameErr} 错误 ");
            }
        }
        private void button_RecordPoint_Click(object sender, EventArgs e)
        {

            string strPointErrName = "";
            try
            {
                if (!UIMessageDialog.ShowMessageDialog("是否记录此点到点位表格！", "Info", true, UIStyle.Blue, true)) return;
                int nAxisNot = _stationBase.AxisX;
                if (dataGridView_PointInfo.CurrentCell != null)
                {
                    int indexRow = dataGridView_PointInfo.CurrentCell.RowIndex;
                    int indexCol = dataGridView_PointInfo.CurrentCell.ColumnIndex;
                    string strPointName = dataGridView_PointInfo.Rows[indexRow].Cells[0].Value.ToString();
                    strPointErrName = strPointName;
                    string[] strPointNameArr = new string[dataGridView_PointInfo.Rows.Count];
                    for (int i = 0; i < dataGridView_PointInfo.Rows.Count; i++)
                    {
                        if (dataGridView_PointInfo.Rows[i].Cells[0].Value != null && dataGridView_PointInfo.Rows[i].Cells[0].Value.ToString() != "")
                            strPointNameArr[i] = dataGridView_PointInfo.Rows[i].Cells[0].Value.ToString();
                    }
                    if(cbb_CoordType.Text == "世界坐标系")
                    {
                        SixRobotPoint tempPoint = new SixRobotPoint();
                        tempPoint = SixRobot.GetCurrentPos_World();
                        dataGridView_PointInfo.Rows[indexRow].Cells[1].Value = Math.Round(tempPoint.X, 3);
                        dataGridView_PointInfo.Rows[indexRow].Cells[2].Value = Math.Round(tempPoint.Y, 3);
                        dataGridView_PointInfo.Rows[indexRow].Cells[3].Value = Math.Round(tempPoint.Z, 3);
                        dataGridView_PointInfo.Rows[indexRow].Cells[4].Value = Math.Round(tempPoint.W, 3);
                        dataGridView_PointInfo.Rows[indexRow].Cells[5].Value = Math.Round(tempPoint.P, 3);
                        dataGridView_PointInfo.Rows[indexRow].Cells[6].Value = Math.Round(tempPoint.R, 3);
                    }
                    else
                    {
                        SixRobotJoint tempPoint = new SixRobotJoint();
                        tempPoint = SixRobot.GetCurrentPos_Joint();
                        dataGridView_PointInfo.Rows[indexRow].Cells[1].Value = Math.Round(tempPoint.A1, 3);
                        dataGridView_PointInfo.Rows[indexRow].Cells[2].Value = Math.Round(tempPoint.A2, 3);
                        dataGridView_PointInfo.Rows[indexRow].Cells[3].Value = Math.Round(tempPoint.A3, 3);
                        dataGridView_PointInfo.Rows[indexRow].Cells[4].Value = Math.Round(tempPoint.A4, 3);
                        dataGridView_PointInfo.Rows[indexRow].Cells[5].Value = Math.Round(tempPoint.A5, 3);
                        dataGridView_PointInfo.Rows[indexRow].Cells[6].Value = Math.Round(tempPoint.A6, 3);
                    }
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(Name, $"{Name}{ex.Message} {ex.StackTrace}");
                this.ShowErrorDialog($"点位数据：{strPointErrName} 错误 ");
            }
        }

        private void EnableBtns(bool bEnable)
        {
            if (cbb_CoordType.SelectedIndex == 0)
            {
                group_MoveL.Enabled = bEnable;
                Group_MoveJ.Enabled = false;
            }
            else
            {
                Group_MoveJ.Enabled = bEnable;
                group_MoveL.Enabled = false;
            }

        }

        private void uiSymbolButton3_Click(object sender, EventArgs e)
        {
            SixRobot.ResetAlarm();
        }

        private void button_ServoOnX_Click(object sender, EventArgs e)
        {
            if (button_ServoOn.Active)
            {
                SixRobot.SetServo(false);
            }
            else
            {
                SixRobot.SetServo(true);
            }
        }
        public void ChangedUserRight(User CurrentUser)
        {
            if (InvokeRequired)
                this.BeginInvoke(new Action(() => ChangedUserRight(CurrentUser)));
            else
            {

                switch ((int)CurrentUser._userRight)
                {
                    case (int)UserRight.Operator:
                        button_RecordPoint.Enabled = false;
                        button_Save.Enabled = false;
                        btnSingleAxisMove.Enabled = false;
                        dataGridView_PointInfo.ReadOnly = true;

                        break;
                    case (int)UserRight.Debug:
                        button_RecordPoint.Enabled = false;
                        button_Save.Enabled = false;
                        btnSingleAxisMove.Enabled = true;
                        dataGridView_PointInfo.ReadOnly = false;
                        break;
                    case (int)UserRight.Software:
                        button_RecordPoint.Enabled = true;
                        button_Save.Enabled = true;
                        btnSingleAxisMove.Enabled = true;

                        dataGridView_PointInfo.ReadOnly = false;
                        break;
                    case (int)UserRight.Admin:
                        button_RecordPoint.Enabled = true;
                        button_Save.Enabled = true;
                        btnSingleAxisMove.Enabled = true;
                        dataGridView_PointInfo.ReadOnly = false;
                        break;
                }
                if ((int)CurrentUser._userRight >= (int)UserRight.Debug)
                {
                    EnableBtns(true);
                }
                else
                {
                    EnableBtns(false);
                }
                UpdatadataGridView_ParamInfo(cbb_ParamType.Text, CurrentUser._userRight);
                GlobalVariable_g_eventStationStateChanged(GlobalVariable.g_StationState);
            }

        }
        void UpdatadataGridView_ParamInfo(string strType, UserRight userRight)
        {
            dataGridView_Param.Rows.Clear();
            Dictionary<string, ParamSet> dic_Param = _stationBase.GetFields<ParamSet>(obj_Param);
            cbb_ParamType.Items.Clear();
            dg_cbb_ParamType.Items.Clear();
            cbb_ParamType.Items.Add("all");
            foreach (var item in dic_Param)
            {
                if (!cbb_ParamType.Items.Contains(item.Value._ParamClass))
                    cbb_ParamType.Items.Add(item.Value._ParamClass);
                if (!dg_cbb_ParamType.Items.Contains(item.Value._ParamClass))
                    dg_cbb_ParamType.Items.Add(item.Value._ParamClass);
                if (item.Value._ParamRight <= userRight)
                {
                    if (item.Value._ParamClass == strType || strType == "all")
                    {
                        int index = dataGridView_Param.Rows.Add(item.Key, item.Value._enuValType.ToString().Trim(),
                          item.Value._strParamVal, item.Value._strParamValMax, item.Value._strParamValMin,
                          item.Value._ParamRight.ToString(), item.Value._ParamClass.ToString(), item.Value.b_IsStartCheck);
                        if ((int)(UserRight)Enum.Parse(typeof(UserRight), dataGridView_Param.Rows[index].Cells[5].Value.ToString()) <= (int)sys.g_User._userRight)
                        {
                            //dataGridView_Param.Rows[index].ReadOnly = false;
                            dataGridView_Param.Rows[index].Cells[0].ReadOnly = true;
                            dataGridView_Param.Rows[index].Cells[1].ReadOnly = true;
                            dataGridView_Param.Rows[index].Cells[2].ReadOnly = false;
                            dataGridView_Param.Rows[index].Cells[3].ReadOnly = false;
                            dataGridView_Param.Rows[index].Cells[4].ReadOnly = false;
                            dataGridView_Param.Rows[index].Cells[5].ReadOnly = false;
                            dataGridView_Param.Rows[index].Cells[6].ReadOnly = false;
                            dataGridView_Param.Rows[index].Cells[7].ReadOnly = false;
                            dataGridView_Param.Rows[index].Visible = true;
                        }
                        else
                        {
                            dataGridView_Param.Rows[index].Cells[0].ReadOnly = true;
                            dataGridView_Param.Rows[index].Cells[1].ReadOnly = true;
                            dataGridView_Param.Rows[index].Cells[2].ReadOnly = true;
                            dataGridView_Param.Rows[index].Cells[3].ReadOnly = true;
                            dataGridView_Param.Rows[index].Cells[4].ReadOnly = true;
                            dataGridView_Param.Rows[index].Cells[5].ReadOnly = true;
                            dataGridView_Param.Rows[index].Cells[6].ReadOnly = true;
                            dataGridView_Param.Rows[index].Cells[7].ReadOnly = true;
                            dataGridView_Param.Rows[index].Visible = true;
                        }
                    }
                }
            }
            cbb_ParamType.Text = strType;
            Language.LanguageHelp.GetInstance().Funtion_TransLate(this.Name);
        }

        private void StationFormRobot_Load(object sender, EventArgs e)
        {
            cbb_CoordType.SelectedIndex = 0;
            for (int i = 0; i < dataGridView_PointInfo.Columns.Count; i++)
            {
                dataGridView_PointInfo.Columns[i].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill;
            }
            UpdatadataGridView_PointInfo();
            ParamSetMgr.GetInstance().m_eventLoadProductFileUpadata += UpdatadataGridView_PointInfo;//更新产品点位置信息
            UpdatadataGridView_ParamInfo("all", sys.g_User._userRight);

            comboBox_SelMotionType.SelectedIndex = 4;

            if (Page_Manual != null)
            {
                tab_ManualTest.Controls.Add(Page_Manual);
                Page_Manual.Show();
            }
            Task.Run(new Action(() =>
            {
                while (true)
                {
                    Thread.Sleep(100);
                    if (BaseDll.GlobalVariable.g_StationState == StationState.StationStateRun)
                        continue;
                    ReflushStatue();
                }
            }));
            sys.g_eventRightChanged += ChangedUserRight;
            GlobalVariable.g_eventStationStateChanged += GlobalVariable_g_eventStationStateChanged;
            GlobalVariable.g_eventControlModeChanged += GlobalVariable_g_eventControlModeChanged;

            GlobalVariable_g_eventStationStateChanged(GlobalVariable.g_StationState);
        }
        private void GlobalVariable_g_eventControlModeChanged(ControlMode currRunMode)
        {
            GlobalVariable_g_eventStationStateChanged(GlobalVariable.g_StationState);
        }

        private void GlobalVariable_g_eventStationStateChanged(StationState currState)
        {
            if (InvokeRequired)
                this.BeginInvoke(new Action(() => GlobalVariable_g_eventStationStateChanged(currState)));
            else
            {
                if ((int)sys.g_User._userRight >= (int)UserRight.Debug && (GlobalVariable.g_StationState == StationState.StationStateEmg || GlobalVariable.g_StationState == StationState.StationStateStop))
                {
                    if ((int)sys.g_User._userRight >= (int)UserRight.Debug &&
                    GlobalVariable.g_ControlMode != ControlMode.Auto)
                    {
                        tabInput.Enabled = true;
                        tabOutput.Enabled = true;
                        PanControl.Enabled = true;
                        propertyGrid_Config.Enabled = true;
                        if (Page_Manual != null)
                            Page_Manual.Enabled = true;
                    }
                    dataGridView_Param.Enabled = true;
                }
                else
                {
                    tabInput.Enabled = false;
                    tabOutput.Enabled = false;
                    PanControl.Enabled = false;
                    Page_Manual.Enabled = false;
                    propertyGrid_Config.Enabled = false;
                    dataGridView_Param.Enabled = false;
                }
            }

        }
        void UpdatadataGridView_PointInfo()
        {
            dataGridView_PointInfo.Rows.Clear();
            if(cbb_CoordType.Text == "世界坐标系")
            {
                Dictionary<string, SixRobotPoint> tempdic = _stationBase.GetFields<SixRobotPoint>(obj_Point);
                foreach (var temp in tempdic)
                {
                    dataGridView_PointInfo.Rows.Add(temp.Key, temp.Value.X.ToString(), temp.Value.Y.ToString(), temp.Value.Z.ToString(), 
                                                   temp.Value.W.ToString(), temp.Value.P.ToString(), temp.Value.R.ToString());
                }
            }
            else
            {
                Dictionary<string, SixRobotJoint> tempdic = _stationBase.GetFields<SixRobotJoint>(obj_Joint);
                if (tempdic == null)
                    return;
                foreach (var temp in tempdic)
                {
                    dataGridView_PointInfo.Rows.Add(temp.Key, temp.Value.A1.ToString(), temp.Value.A2.ToString(), temp.Value.A3.ToString(),
                                                   temp.Value.A4.ToString(), temp.Value.A5.ToString(), temp.Value.A6.ToString());
                }

            }
            Language.LanguageHelp.GetInstance().Funtion_TransLate(this.Name);

        }

        private void btnStop_Click(object sender, EventArgs e)
        {
            SixRobot.Stop();
        }
        private void btnSingleAxisMove_Click(object sender, EventArgs e)
        {
            if (!UIMessageDialog.ShowMessageDialog("是否进行单轴运动，请注意安全！", "Info", true, UIStyle.Blue, true)) return;
            if (dataGridView_PointInfo.CurrentCell == null)
                return;
            int indexRow = dataGridView_PointInfo.CurrentCell.RowIndex;
            EnableBtns(false);
            Task.Run(new Action(() =>
            {
                if(strCoordName == "世界坐标系")
                {
                    SixRobotPoint point = new SixRobotPoint();
                    int index = 1;
                    point.X = Convert.ToDouble(dataGridView_PointInfo.Rows[indexRow].Cells[index++].Value);
                    point.Y = Convert.ToDouble(dataGridView_PointInfo.Rows[indexRow].Cells[index++].Value);
                    point.Z = Convert.ToDouble(dataGridView_PointInfo.Rows[indexRow].Cells[index++].Value);
                    point.W = Convert.ToDouble(dataGridView_PointInfo.Rows[indexRow].Cells[index++].Value);
                    point.P = Convert.ToDouble(dataGridView_PointInfo.Rows[indexRow].Cells[index++].Value);
                    point.R = Convert.ToDouble(dataGridView_PointInfo.Rows[indexRow].Cells[index++].Value);
                    SixRobot.MoveLine(point,true);
                }
                else
                {
                    SixRobotJoint point = new SixRobotJoint();
                    int index = 1;
                    point.A1 = Convert.ToDouble(dataGridView_PointInfo.Rows[indexRow].Cells[index++].Value);
                    point.A2 = Convert.ToDouble(dataGridView_PointInfo.Rows[indexRow].Cells[index++].Value);
                    point.A3 = Convert.ToDouble(dataGridView_PointInfo.Rows[indexRow].Cells[index++].Value);
                    point.A4 = Convert.ToDouble(dataGridView_PointInfo.Rows[indexRow].Cells[index++].Value);
                    point.A5 = Convert.ToDouble(dataGridView_PointInfo.Rows[indexRow].Cells[index++].Value);
                    point.A6 = Convert.ToDouble(dataGridView_PointInfo.Rows[indexRow].Cells[index++].Value);
                    SixRobot.MoveJog(point, true, 100,500);
                }
                Thread.Sleep(100);
                BeginInvoke(new Action(() =>
                {
                    EnableBtns(true);
                }));
            }));
        }

        private void cbb_ParamType_SelectedIndexChanged_1(object sender, EventArgs e)
        {
            UpdatadataGridView_ParamInfo(cbb_ParamType.Text, sys.g_User._userRight);
        }
        List<string> ItemName = new List<string>();
        private bool Check()
        {
            try
            {
                ItemName.Clear();
                for (int i = 0; i < dataGridView_Param.Rows.Count; i++)
                {
                    string name = dataGridView_Param.Rows[i].Cells[0].Value.ToString().Trim();
                    string sort = dataGridView_Param.Rows[i].Cells[6].Value.ToString().Trim();
                    string type = dataGridView_Param.Rows[i].Cells[1].Value.ToString().Trim();
                    string value = dataGridView_Param.Rows[i].Cells[2].Value.ToString().Trim();
                    string Max = dataGridView_Param.Rows[i].Cells[3].Value.ToString().Trim();
                    string Min = dataGridView_Param.Rows[i].Cells[4].Value.ToString().Trim();
                    dynamic v; dynamic vMax; dynamic vMin;

                    if (type == "boolUnit")
                    {
                        if (value.ToLower() != "true" && value.ToLower() != "false")
                        {
                            UIMessageBox.ShowError($"类别:{sort}名称:{name}，value设置失败，请输入false或者true");
                            return false;
                        }
                        if (Max.ToLower() != "true" && Max.ToLower() != "false")
                        {
                            UIMessageBox.ShowError($"类别:{sort}名称:{name}，Max设置失败，请输入false或者true");
                            return false;
                        }
                        if (Min.ToLower() != "true" && Min.ToLower() != "false")
                        {
                            UIMessageBox.ShowError($"类别:{sort}名称:{name}，min设置失败，请输入false或者true");
                            return false;
                        }
                    }
                    else if (type == "intUnit")
                    {

                        if (value.Contains("."))
                        {
                            UIMessageBox.ShowError($"类别:{sort}名称:{name}，value设置失败，有小数点");
                            return false;
                        }
                        if (Max.Contains("."))
                        {
                            UIMessageBox.ShowError($"类别:{sort}名称:{name}，Max设置失败，有小数点");
                            return false;
                        }
                        if (Min.Contains("."))
                        {
                            UIMessageBox.ShowError($"类别:{sort}名称:{name}，min设置失败，有小数点");
                            return false;
                        }
                        try
                        {
                            v = Convert.ToInt32(value);
                        }
                        catch
                        {
                            UIMessageBox.ShowError($"类别:{sort}名称:{name}，value设置失败，请输入int类型数据");
                            return false;
                        }
                        try
                        {
                            vMax = Convert.ToInt32(Max);
                        }
                        catch
                        {
                            UIMessageBox.ShowError($"类别:{sort}名称:{name}，Max设置失败，请输入int类型数据");
                            return false;
                        }
                        try
                        {
                            vMin = Convert.ToInt32(Min);
                        }
                        catch
                        {
                            UIMessageBox.ShowError($"类别:{sort}名称:{name}，min设置失败，请输入int类型数据");
                            return false;
                        }
                        if (v > vMax || v < vMin)
                        {
                            UIMessageBox.ShowError($"类别:{sort}名称:{name}，value设置失败，不在规格内");
                            return false;
                        }
                    }
                    else if (type == "doubleUnit")
                    {
                        try
                        {
                            v = Convert.ToDouble(value);
                        }
                        catch
                        {
                            UIMessageBox.ShowError($"类别:{sort}名称:{name}，value设置失败，请输入int类型数据");
                            return false;
                        }
                        try
                        {
                            vMax = Convert.ToDouble(Max);
                        }
                        catch
                        {
                            UIMessageBox.ShowError($"类别:{sort}名称:{name}，Max设置失败，请输入int类型数据");
                            return false;
                        }
                        try
                        {
                            vMin = Convert.ToDouble(Min);
                        }
                        catch
                        {
                            UIMessageBox.ShowError($"类别:{sort}名称:{name}，min设置失败，请输入int类型数据");
                            return false;
                        }
                        if (v > vMax || v < vMin)
                        {
                            UIMessageBox.ShowError($"类别:{sort}名称:{name}，value设置失败，不在规格内");
                            return false;
                        }

                    }
                    else if (type == "stringUnit")
                    {

                    }
                    if (ItemName.Contains(name))
                    {
                        UIMessageBox.ShowError($"第{i}行存在重名参数{name},请检查");
                        return false;
                    }
                    ItemName.Add(name);
                }
                return true;
            }
            catch (Exception ex)
            {
                MessageBox.Show(Name, $"{Name}{ex.Message} {ex.StackTrace}");
                return false;
            }

        }

        private void btn_SaveParam_Click_1(object sender, EventArgs e)
        {
            try
            {
                if (!this.ShowAskDialog("是否保存该工站参数！", UIStyle.Blue)) return;
                if (!Check())
                    return;
                Dictionary<string, ParamSet> staParam_New = _stationBase.GetFields<ParamSet>(obj_Param);
                for (int i = 0; i < dataGridView_Param.Rows.Count; i++)
                {
                    if (dataGridView_Param.Rows[i].Cells[0].Value != null && dataGridView_Param.Rows[i].Cells[0].Value.ToString() != "")
                    {
                        int nIndexOfMax = 3;
                        int nIndexOfMin = 4;
                        int nIndexOfVal = 2;
                        int nIndexOfClass = 6;
                        int nIndexOfRight = 5;
                        int nIndexOfName = 0;
                        int nIndexOfUnit = 1;
                        int nIndexOfbIsStartCheck = 7;
                        string strParamName = Language.LanguageHelp.GetInstance().Function_TransToChinese(this.Name, dataGridView_Param.Rows[i].Cells[nIndexOfName].Value.ToString());
                        string strValType = Language.LanguageHelp.GetInstance().Function_TransToChinese(this.Name, dataGridView_Param.Rows[i].Cells[nIndexOfUnit].Value.ToString());
                        string strParamVal = Language.LanguageHelp.GetInstance().Function_TransToChinese(this.Name, dataGridView_Param.Rows[i].Cells[nIndexOfVal].Value.ToString());
                        string strParamValMax = Language.LanguageHelp.GetInstance().Function_TransToChinese(this.Name, dataGridView_Param.Rows[i].Cells[nIndexOfMax].Value.ToString());
                        string strParamValMin = Language.LanguageHelp.GetInstance().Function_TransToChinese(this.Name, dataGridView_Param.Rows[i].Cells[nIndexOfMin].Value.ToString());
                        string strParamRight = dataGridView_Param.Rows[i].Cells[nIndexOfRight].Value.ToString();
                        string strParamClass = Language.LanguageHelp.GetInstance().Function_TransToChinese(this.Name, dataGridView_Param.Rows[i].Cells[nIndexOfClass].Value.ToString());
                        ParamSet paramSet = new ParamSet()
                        {
                            _strParamUnit = strParamName,
                            _enuValType = dataGridView_Param.Rows[i].Cells[nIndexOfUnit].Value == null ? ParamSetUnit.doubleUnit : (ParamSetUnit)Enum.Parse(typeof(ParamSetUnit), strValType),
                            _strParamVal = dataGridView_Param.Rows[i].Cells[nIndexOfVal].Value == null ? "0" : strParamVal,
                            _strParamValMax = dataGridView_Param.Rows[i].Cells[nIndexOfMax].Value == null ? "0" : strParamValMax,
                            _strParamValMin = dataGridView_Param.Rows[i].Cells[nIndexOfMin].Value == null ? "0" : strParamValMin,
                            _ParamRight = dataGridView_Param.Rows[i].Cells[nIndexOfRight].Value == null ? UserRight.Operator : (UserRight)Enum.Parse(typeof(UserRight), strParamRight),
                            _ParamClass = dataGridView_Param.Rows[i].Cells[nIndexOfClass].Value == null ? "综合" : strParamClass,
                            b_IsStartCheck = Convert.ToBoolean(dataGridView_Param.Rows[i].Cells[nIndexOfbIsStartCheck].Value)
                        };
                        if (paramSet._enuValType == ParamSetUnit.boolUnit)
                        {
                            paramSet._strParamVal = Convert.ToBoolean(paramSet._strParamVal);
                            paramSet._strParamValMax = Convert.ToBoolean(paramSet._strParamValMax);
                            paramSet._strParamValMin = Convert.ToBoolean(paramSet._strParamValMin);
                        }
                        else if (paramSet._enuValType == ParamSetUnit.doubleUnit)
                        {
                            paramSet._strParamVal = Convert.ToDouble(paramSet._strParamVal);
                            paramSet._strParamValMax = Convert.ToDouble(paramSet._strParamValMax);
                            paramSet._strParamValMin = Convert.ToDouble(paramSet._strParamValMin);
                        }
                        else if (paramSet._enuValType == ParamSetUnit.intUnit)
                        {
                            paramSet._strParamVal = Convert.ToInt32(paramSet._strParamVal);
                            paramSet._strParamValMax = Convert.ToInt32(paramSet._strParamValMax);
                            paramSet._strParamValMin = Convert.ToInt32(paramSet._strParamValMin);
                        }
                        else if (paramSet._enuValType == ParamSetUnit.stringUnit)
                        {
                            paramSet._strParamVal = Convert.ToString(paramSet._strParamVal);
                            paramSet._strParamValMax = Convert.ToString(paramSet._strParamValMax);
                            paramSet._strParamValMin = Convert.ToString(paramSet._strParamValMin);
                        }
                        string str_PointInfo = $"站位名称：{this.Name}，参数名称：{strParamName}，参数值：{strParamVal}";
                        staParam_New[strParamName] = paramSet;
                    }
                }
                if (obj_Param == null) return;
                FieldInfo[] list_Field = obj_Param.GetType().GetFields(BindingFlags.NonPublic | BindingFlags.Public | BindingFlags.Instance);
                if (list_Field.Length <= 0) return;
                foreach (var item in list_Field)
                {
                    string str_Name = item.Name;
                    for (int i = 0; i < staParam_New.Count; i++)
                    {
                        if (item.Name == staParam_New.Keys.ToList()[i])
                        {
                            ParamSet paramOld = (ParamSet)item.GetValue(obj_Param);
                            ParamSet paramNew = staParam_New.Values.ToList()[i];
                            if (paramOld._strParamVal != paramNew._strParamVal)
                                BaseDll.DeviceDataCollect.GetInstance().Function_ParamChangeLog(this.Name, str_Name, Convert.ToString(paramOld._strParamVal), Convert.ToString(paramNew._strParamVal), "值");
                            if (paramOld._strParamValMax != paramNew._strParamValMax)
                                BaseDll.DeviceDataCollect.GetInstance().Function_ParamChangeLog(this.Name, str_Name, Convert.ToString(paramOld._strParamValMax), Convert.ToString(paramNew._strParamValMax), "最大值");
                            if (paramOld._strParamValMin != paramNew._strParamValMin)
                                BaseDll.DeviceDataCollect.GetInstance().Function_ParamChangeLog(this.Name, str_Name, Convert.ToString(paramOld._strParamValMin), Convert.ToString(paramNew._strParamValMin), "最小值");


                            item.SetValue(obj_Param, staParam_New.Values.ToList()[i]);
                        }
                    }
                }

                ConfigToolMgr.GetInstance().SaveStationParam(this.Name, staParam_New);
                for (int i = 0; i < dataGridView_Param.RowCount; i++)
                {

                    if (dataGridView_Param.Rows[i].Cells[2].Style.BackColor == Color.Yellow)
                        dataGridView_Param.Rows[i].Cells[2].Style.BackColor = Color.White;
                    if (dataGridView_Param.Rows[i].Cells[3].Style.BackColor == Color.Yellow)
                        dataGridView_Param.Rows[i].Cells[3].Style.BackColor = Color.White;
                    if (dataGridView_Param.Rows[i].Cells[4].Style.BackColor == Color.Yellow)
                        dataGridView_Param.Rows[i].Cells[4].Style.BackColor = Color.White;
                }

            }
            catch (Exception ex)
            {
                MessageBox.Show(Name, $"{Name}{ex.Message} {ex.StackTrace}");
            }

        }

        private void button_ServoOn_ValueChanged(object sender, bool value)
        {

        }

        private void dataGridView_Param_CellDoubleClick(object sender, DataGridViewCellEventArgs e)
        {
            try
            {
                int RowIndex = dataGridView_Param.CurrentCell.RowIndex;
                int ColumnIndex = dataGridView_Param.CurrentCell.ColumnIndex;
                if (ColumnIndex == 2 || ColumnIndex == 3 || ColumnIndex == 4)
                {
                    string valType = ColumnIndex == 2 ? "参数值" : ColumnIndex == 3 ? " 最大值" : "最小值";
                    string oldData = dataGridView_Param[ColumnIndex, RowIndex].Value?.ToString();
                    string paramname = dataGridView_Param[0, RowIndex].Value.ToString();
                    if (ColumnIndex == 2 && (dataGridView_Param[1, RowIndex].Value != null &&
                         dataGridView_Param[3, RowIndex].Value != null &&
                         dataGridView_Param[4, RowIndex].Value != null
                         ))
                    {

                        InputDataToDataGridView(RowIndex, ColumnIndex, dataGridView_Param[3, RowIndex].Value.ToString(), dataGridView_Param[4, RowIndex].Value.ToString());
                        string newData = dataGridView_Param[ColumnIndex, RowIndex].Value.ToString();
                        UIMessageTipHelper.ShowInfoTip(dataGridView_Param.GetParentForm(), $"参数：{paramname}  {valType}被修改 原值：{oldData} --> 现值:{newData}", TipStyle.Gray, 1500);
                    }
                    if (dataGridView_Param[1, RowIndex].Value != null && (ColumnIndex == 3 || ColumnIndex == 4))
                    {
                        InputDataToDataGridView(RowIndex, ColumnIndex, "", "");
                        string newData = dataGridView_Param[ColumnIndex, RowIndex].Value.ToString();
                        UIMessageTipHelper.ShowInfoTip(dataGridView_Param.GetParentForm(), $"参数：{paramname} {valType}被修改 原值：{oldData} --> 现值:{newData}", TipStyle.Gray, 1500);

                    }

                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(Name, $"{Name}{ex.Message} {ex.StackTrace}");
            }

        }

        private void InputDataToDataGridView(int RowIndex, int ColumnIndex, string max, string min)
        {
            bool bRtnInput = false;
            switch (Enum.Parse(typeof(ParamSetUnit), dataGridView_Param[1, RowIndex].Value?.ToString()))
            {

                case ParamSetUnit.intUnit:
                    int nMax = max != "" ? max.ToInt() : int.MaxValue;
                    int nMin = min != "" ? min.ToInt() : int.MinValue;

                    int valueInt = dataGridView_Param[ColumnIndex, RowIndex].Value == null ? 0 : dataGridView_Param[ColumnIndex, RowIndex].Value.ToString().ToInt();
                    bRtnInput = UIInputDialog.InputIntegerDialog(this, ref valueInt, true, "请输入数字：");
                    if (bRtnInput)
                    {

                        if (dataGridView_Param[ColumnIndex, RowIndex].Value?.ToString().ToInt() != valueInt)
                        {
                            ChangeDataGridViewCellBackColor(dataGridView_Param, RowIndex, ColumnIndex);
                            dataGridView_Param[ColumnIndex, RowIndex].Value = valueInt;
                        }
                    }
                    int dOldValint = dataGridView_Param[ColumnIndex, RowIndex].Value == null ? 0 : dataGridView_Param[ColumnIndex, RowIndex].Value.ToString().ToInt();
                    if (valueInt == dOldValint) bRtnInput = true;
                    break;
                case ParamSetUnit.doubleUnit:
                    double dMax = max != "" ? max.ToDouble() : double.MaxValue;
                    double dMin = min != "" ? min.ToDouble() : double.MinValue;
                    double valueDouble = dataGridView_Param[ColumnIndex, RowIndex].Value == null ? 0 : dataGridView_Param[ColumnIndex, RowIndex].Value.ToString().ToDouble();
                    bRtnInput = UIInputDialog.InputDoubleDialog(this, ref valueDouble, 3, true, "请输入数字：");
                    if (bRtnInput)
                    {
                        if (dataGridView_Param[ColumnIndex, RowIndex].Value?.ToString().ToDouble() != valueDouble)
                        {

                            ChangeDataGridViewCellBackColor(dataGridView_Param, RowIndex, ColumnIndex);
                            dataGridView_Param[ColumnIndex, RowIndex].Value = valueDouble;
                        }
                    }
                    double dOldValdouble = dataGridView_Param[ColumnIndex, RowIndex].Value == null ? 0 : dataGridView_Param[ColumnIndex, RowIndex].Value.ToString().ToDouble();
                    if (valueDouble == dOldValdouble)
                        bRtnInput = true;
                    break;
                case ParamSetUnit.boolUnit:
                    int selectIndex = dataGridView_Param[ColumnIndex, RowIndex].Value == null ? 0 : dataGridView_Param[ColumnIndex, RowIndex].Value.ToString().ToUpper() == "TRUE" ? 0 : 1;
                    List<string> items = new List<string>() { "True", "False" };
                    bRtnInput = this.ShowSelectDialog(ref selectIndex, items, "是否选择".Trim(), "", UIStyle.Blue);
                    if (bRtnInput)
                    {
                        if (dataGridView_Param[ColumnIndex, RowIndex].Value?.ToString() != items[selectIndex])
                        {
                            ChangeDataGridViewCellBackColor(dataGridView_Param, RowIndex, ColumnIndex);
                            dataGridView_Param[ColumnIndex, RowIndex].Value = items[selectIndex];
                        }
                    }
                    if (dataGridView_Param[ColumnIndex, RowIndex].Value?.ToString() == items[selectIndex])
                        bRtnInput = true;


                    break;
                case ParamSetUnit.stringUnit:
                    string valueString = dataGridView_Param[ColumnIndex, RowIndex].Value == null ? "" : dataGridView_Param[ColumnIndex, RowIndex].Value.ToString();
                    bRtnInput = UIInputDialog.InputStringDialog(this, ref valueString, false, "请输入字符：");
                    if (bRtnInput)
                    {
                        if (dataGridView_Param[ColumnIndex, RowIndex].Value?.ToString() != valueString)
                        {
                            dataGridView_Param[ColumnIndex, RowIndex].Value = valueString;
                            ChangeDataGridViewCellBackColor(dataGridView_Param, RowIndex, ColumnIndex);
                        }
                    }
                    if (valueString == dataGridView_Param[ColumnIndex, RowIndex].Value?.ToString())
                        bRtnInput = true;

                    break;

            }
            if (!bRtnInput)
                this.ShowMessageDialog("输入值错误，可能超出上下限，请检查", "Err", true, UIStyle.Blue);
        }
        public void ChangeDataGridViewCellBackColor(DataGridView dataGridView, int RowIndex, int ColumnIndex)
        {
            DataGridViewRow dr = (dataGridView as DataGridView).Rows[RowIndex];
            dr.Cells[ColumnIndex].Style.BackColor = Color.Yellow;
            dataGridView_Param.Invalidate(dr.Cells[ColumnIndex].ContentBounds);
            dr.Cells[ColumnIndex].Selected = false;
        }

        private void dataGridView_Param_Click(object sender, EventArgs e)
        {
            try
            {
                int RowIndex = dataGridView_Param.CurrentCell.RowIndex;
                int ColumnIndex = dataGridView_Param.CurrentCell.ColumnIndex;
                if (ColumnIndex >= 0 && RowIndex >= 0)
                {
                    richTxt_参数说明.Text = $"参数名:{ dataGridView_Param[0, RowIndex].Value}" + Environment.NewLine;
                    richTxt_参数说明.Text += $"当前值:{ dataGridView_Param[2, RowIndex].Value}" + Environment.NewLine;
                    richTxt_参数说明.Text += $"允许最大值:{ dataGridView_Param[3, RowIndex].Value}" + Environment.NewLine;
                    richTxt_参数说明.Text += $"允许最小值:{ dataGridView_Param[4, RowIndex].Value}" + Environment.NewLine;
                    if (dataGridView_Param[0, RowIndex].Value == null)
                        return;
                    var de = ParamSetMgr.GetInstance().paramValue?.Find(p => p.ParamName == (dataGridView_Param[0, RowIndex].Value).ToString().Trim());
                    if (de == null)
                    {
                        richTxt_参数说明.Text += $"参数描述:还未添加描述，请在Description.xml中添加" + Environment.NewLine;
                    }
                    else
                    {
                        richTxt_参数说明.Text += $"参数描述:{ de.Description}" + Environment.NewLine;
                    }


                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(Name, $"{Name}{ex.Message} {ex.StackTrace}");
                return;
            }

        }

        private void btn_ConfigSave_Click(object sender, EventArgs e)
        {
            try
            {
                CommonTools.ConfigToolMgr.GetInstance().SaveStationConfig(this.Name, propertyGrid_Config.SelectedObject);
            }
            catch (Exception ex)
            {
                MessageBox.Show(Name, $"{Name}{ex.Message} {ex.StackTrace}");
                return;
            }

        }
        bool b_ConnectState = false;
        bool b_Servo = false;
        SixRobotPoint sixPoint = new SixRobotPoint();
        SixRobotJoint sixJoint = new SixRobotJoint();
        void ReflushStatue()
        {
            try
            {
                bool b_Connect = SixRobot.IsConnect();
                if (b_ConnectState != b_Connect)
                {
                    BeginInvoke(new Action(() =>
                    {
                        lbl_ConnectState.Text = b_ConnectState ? "已连接" : "未连接";
                        lbl_ConnectState.BackColor = b_ConnectState ? Color.Green : Color.Red;
                    }));
                }
                b_ConnectState = b_Connect;
                bool b_On = SixRobot.ReadServoStatue();
                if (b_Servo != b_On)
                {
                    BeginInvoke(new Action(() =>
                    {
                        button_ServoOn.Active = b_On;
                    }));
                }
                b_Servo = b_On;
                if (strCoordName == "世界坐标系")
                {
                    SixRobotPoint point = SixRobot.GetCurrentPos_World();
                    BeginInvoke(new Action(() =>
                    {
                        if (point.X != sixPoint.X)
                            label_A1Data.Text = point.X.ToString("0.000");
                        if (point.Y != sixPoint.Y)
                            label_A2Data.Text = point.Y.ToString("0.000");
                        if (point.Z != sixPoint.Z)
                            label_A3Data.Text = point.Z.ToString("0.000");
                        if (point.W != sixPoint.W)
                            label_A4Data.Text = point.W.ToString("0.000");
                        if (point.P != sixPoint.P)
                            label_A5Data.Text = point.P.ToString("0.000");
                        if (point.R != sixPoint.R)
                            label_A6Data.Text = point.R.ToString("0.000");
                        sixPoint = point;
                        sixJoint = new SixRobotJoint();
                    }));

                }
                else
                {
                    SixRobotJoint point = SixRobot.GetCurrentPos_Joint();
                    BeginInvoke(new Action(() =>
                    {
                        if (point.A1 != sixJoint.A1)
                            label_A1Data.Text = point.A1.ToString("0.000");
                        if (point.A2 != sixJoint.A2)
                            label_A2Data.Text = point.A2.ToString("0.000");
                        if (point.A3 != sixJoint.A3)
                            label_A3Data.Text = point.A3.ToString("0.000");
                        if (point.A4 != sixJoint.A4)
                            label_A4Data.Text = point.A4.ToString("0.000");
                        if (point.A5 != sixJoint.A5)
                            label_A5Data.Text = point.A5.ToString("0.000");
                        if (point.A6 != sixJoint.A6)
                            label_A6Data.Text = point.A6.ToString("0.000");
                        sixJoint = point;
                        sixPoint = new SixRobotPoint();
                    }));
                }
            }
            catch (Exception)
            {

            }


        }


        private void cbb_CoordType_SelectedIndexChanged(object sender, EventArgs e)
        {
            try
            {
                UpdatadataGridView_PointInfo();
                if (cbb_CoordType.SelectedIndex == 0)
                {
                    lbl_A1.Text = "X";
                    lbl_A2.Text = "Y";
                    lbl_A3.Text = "Z";
                    lbl_A4.Text = "W";
                    lbl_A5.Text = "P";
                    lbl_A6.Text = "R";
                }
                else
                {
                    lbl_A1.Text = "A1";
                    lbl_A2.Text = "A2";
                    lbl_A3.Text = "A3";
                    lbl_A4.Text = "A4";
                    lbl_A5.Text = "A5";
                    lbl_A6.Text = "A6";
                }
                strCoordName = cbb_CoordType.Text;
                EnableBtns(true);
            }
            catch (Exception)
            {

                throw;
            }
        }

        private void button_JogStep_Click(object sender, EventArgs e)
        {
            try
            {
                string strSelDistance = comboBox_SelMotionType.SelectedItem.ToString();
                double d_Dis = strSelDistance.ToDouble();
                SixRobotJoint point = SixRobot.GetCurrentPos_Joint();
                UISymbolButton button = (UISymbolButton)sender;
                if (button.Text == "A1-")
                {
                    point.A1 = point.A1 - d_Dis;
                }
                else if (button.Text == "A1+")
                {
                    point.A1 = point.A1 + d_Dis;
                }
                else if (button.Text == "A2-")
                {
                    point.A2 = point.A2 - d_Dis;

                }
                else if (button.Text == "A2+")
                {
                    point.A2 = point.A2 + d_Dis;

                }
                else if (button.Text == "A3-")
                {
                    point.A3 = point.A3 - d_Dis;

                }
                else if (button.Text == "A3+")
                {
                    point.A3 = point.A3 + d_Dis;

                }
                else if (button.Text == "A4-")
                {
                    point.A4 = point.A4 - d_Dis;

                }
                else if (button.Text == "A4+")
                {
                    point.A4 = point.A4 + d_Dis;

                }
                else if (button.Text == "A5-")
                {
                    point.A5 = point.A5 - d_Dis;

                }
                else if (button.Text == "A5+")
                {
                    point.A5 = point.A5 + d_Dis;

                }
                else if (button.Text == "A6-")
                {
                    point.A6 = point.A6 - d_Dis;
                }
                else if (button.Text == "A6+")
                {
                    point.A6 = point.A6 + d_Dis;
                }
                EnableBtns(false);
                Task.Run(new Action(() =>
                {
                    SixRobot.MoveJog(point, true, 100, 500);
                    Thread.Sleep(100);
                    BeginInvoke(new Action(() =>
                    {
                        EnableBtns(true);
                    }));
                }));
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }

        private void button_WorldMove_Click(object sender, EventArgs e)
        {
            try
            {
                string strSelDistance = comboBox_SelMotionType.SelectedItem.ToString();
                double d_Dis = strSelDistance.ToDouble();
                SixRobotPoint point = SixRobot.GetCurrentPos_World();
                UISymbolButton button = (UISymbolButton)sender;
                if (button.Text == "X-")
                {
                    point.X = point.X - d_Dis;
                }
                else if (button.Text == "X+")
                {
                    point.X = point.X + d_Dis;
                }
                else if (button.Text == "Y-")
                {
                    point.Y = point.Y - d_Dis;

                }
                else if (button.Text == "Y+")
                {
                    point.Y = point.Y + d_Dis;

                }
                else if (button.Text == "Z-")
                {
                    point.Z = point.Z - d_Dis;

                }
                else if (button.Text == "Z+")
                {
                    point.Z = point.Z + d_Dis;

                }
                else if (button.Text == "W-")
                {
                    point.W = point.W - d_Dis;

                }
                else if (button.Text == "W+")
                {
                    point.W = point.W + d_Dis;

                }
                else if (button.Text == "P-")
                {
                    point.P = point.P - d_Dis;

                }
                else if (button.Text == "P+")
                {
                    point.P = point.P + d_Dis;

                }
                else if (button.Text == "R-")
                {
                    point.R = point.R - d_Dis;
                }
                else if (button.Text == "R+")
                {
                    point.R = point.R + d_Dis;
                }
                EnableBtns(false);
                Task.Run(new Action(() =>
                {
                    SixRobot.MoveLine(point, true, 100, 500);
                    Thread.Sleep(100);
                    BeginInvoke(new Action(() =>
                    {
                        EnableBtns(true);
                    }));
                }));
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }

        }

        private void dataGridView_Param_DataError(object sender, DataGridViewDataErrorEventArgs e)
        {

        }
    }
}
